<?php
namespace app\sysAdmin\controller;
use app\common\Base;
use app\common\TeacherModel;
use think\Db;

class ClassTeacher extends Base {
	
	public function index() {
		return $this->fetch();
	}

	public function pageQuery() {
		if(request()->isPost()){
			$page = input('page');
			$rows = input('rows');
			$where["班主任科任.年级号"] = array("gt", currTerm()["finishedKey"]);
			$grade = input("grade");
			$clazz = input("clazz");
			if($grade) {
				$array = explode("_", $grade);
				$where["班主任科任.年级号"] = array("eq", $array[0]);
				$where["班主任科任.学籍类型"] = array("eq", $array[1]);
			}
			if($clazz) {
				$where["班主任科任.年级号"] = array("eq", $clazz);
			}
			$Model = new TeacherModel();
			return $Model->getClassTeacherList($page, $rows, $where);
		}
	}

	public function addUpdate() {
		$all = request()->param();
		try {
			if(array_key_exists("年级号", $all)) {
				$array = explode("_", $all["年级号"]);
				$all["年级号"] = $array[0];
				$all["学籍类型"] = $array[1];
			}
			if(array_key_exists("ID", $all)) {
				update('班主任科任', $all);
			} else {
				insert('班主任科任', $all);
			}
			return "000";
		} catch (Exception $e) {
			echo $e->getMessage();
		}
		return "999";
	}

	public function del() {
		$delIds = input("delIds");
		try {
			Db::name('班主任科任')->where('ID','in',explode(",", $delIds))->delete();
			return "000";
		} catch (Exception $e) {
			echo $e->getMessage();
		}
		return "999";
	}

}
